package com.yinhe.system.controller;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.SysTask;
import com.yinhe.system.service.ISysTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 任务记录Controller
 * 
 * @author ChenMu
 * @date 2022-05-15
 */
@RestController
@RequestMapping("/system/task")
public class SysTaskController extends BaseController
{
    @Autowired
    private ISysTaskService sysTaskService;

    /**
     * 查询任务记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTask sysTask)
    {
        startPage();
        List<SysTask> list = sysTaskService.selectSysTaskList(sysTask);
        return getDataTable(list);
    }

    /**
     * 导出任务记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:export')")
    @Log(title = "任务记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysTask sysTask)
    {
        List<SysTask> list = sysTaskService.selectSysTaskList(sysTask);
        ExcelUtil<SysTask> util = new ExcelUtil<SysTask>(SysTask.class);
        util.exportExcel(response, list, "任务记录数据");
    }

    /**
     * 获取任务记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Integer taskId)
    {
        return AjaxResult.success(sysTaskService.selectSysTaskByTaskId(taskId));
    }

    /**
     * 新增任务记录
     */
    @PreAuthorize("@ss.hasPermi('system:task:add')")
    @Log(title = "任务记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTask sysTask)
    {
        return toAjax(sysTaskService.insertSysTask(sysTask));
    }

    /**
     * 修改任务记录
     */
    @PreAuthorize("@ss.hasPermi('system:task:edit')")
    @Log(title = "任务记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTask sysTask)
    {
        return toAjax(sysTaskService.updateSysTask(sysTask));
    }

    /**
     * 删除任务记录
     */
    @PreAuthorize("@ss.hasPermi('system:task:remove')")
    @Log(title = "任务记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Integer[] taskIds)
    {
        return toAjax(sysTaskService.deleteSysTaskByTaskIds(taskIds));
    }
}
